package backend;

import java.util.HashMap;
import java.util.Map;

public class RegistersMap {

	Map<String, Integer> registers = new HashMap<String, Integer>();

	public int get(String reg) {
		if (static_methods.checkPresence(reg, registers))
			return registers.get(reg);
		System.out.println("error in get() in registersMap.java");
//		System.exit(0);
		return 0;
	}

	public boolean put(String reg, int val) {
		if (static_methods.checkPresence(reg, registers)) {
			registers.put(reg, val);
			return true;
		}
		System.out.println("error in put() in registersMap.java");
		return false;
	}

	public void reset() {
		final Integer zero = 0;
		registers.put("zero", zero);
		registers.put("$at", 0);
		this.init('v', 2);
		this.init('a', 4);
		this.init('t', 8);
		this.init('s', 8);
		registers.put("$t8", 0);
		registers.put("t9", 0);
		this.init('k', 2);
		registers.put("$gb", 0);
		registers.put("$sp", 0);
		registers.put("$fp", 0);
		registers.put("$ra", 0);
	}

	public void init(char c, int n) {
		for (int i = 0; i < n; i++)
			registers.put("$" + c + "" + i, 0);
	}

}
